<!DOCTYPE HTML>
<html>
<head>
	<title>我的个人博客</title>
	<meta charset="utf8">
	<link rel="stylesheet" type="text/css" href="style.css">
	<link rel="icon" type="image/png" href="simbs.png">
</head>
<body>

<div class="top">
	<div class="header"> 
		<div class="logo">
			<a href="index.php"><img src="logo.png"/></a>
		</div>
		<div id="container">
			<ul>
<?php
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());

	$sql = "select * from catalogs";
	$res = mysql_query($sql,$conn);
	while($row=mysql_fetch_assoc($res)){
		$cid = $row['cid'];
		echo "<li><a href=blogManage.php?list=$cid>{$row['catalog']}</a></li>";
	}
	mysql_free_result($res);
	mysql_close($conn);
?>
			</ul>
		</div>
	</div>
	<div class="single">
		<div class="content">
			<form action="blogProcess.php" method="post" > 添加新文章<br />
				<input type="text" name="title" /><br />
				 <textarea name="content" rows="10" cols="70"></textarea><br/>
				<select name="cid">
<?php
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());
	
	$sql = "select * from catalogs ";
	$res = mysql_query($sql,$conn);
	while($row=mysql_fetch_assoc($res)){
		echo "<option value={$row['cid']}>{$row['catalog']}</option>";
	}
	mysql_free_result($res);
	mysql_close($conn);
?>
				</select>
				<input type="submit" value="发布文章"/>			
			</form>
		</div>
	</div>
	<div class="sidebar">
		<div class="loginSuccess">
			<?php
				session_start();
				if(!empty($_SESSION['name'])){
				echo "当前用户: ".$_SESSION['name']."<br />";
                                echo "<a href='blogList.php'>管理博文</a><br/>";
                                echo "<a href='blogAdd.php'>添加博文</a><br/>";
                                echo "<a href='configManage.php'>管理设置</a><br/>";
				echo "<a href='login.php'>重新登录</a>";
				} else{
				echo "<a href='login.php'>用户登录</a>";
				}
                ?>      

		</div>
                <div class="latest">最近更新
                <ul>
<?php
	//调用配置文件config.php
	require_once 'config.php';
	//连接数据库 
	$conn = mysql_connect($host, $dbusername,$dbpassword);
	if(!$conn){
		die("连接失败".mysql_error());
	}
	//设置访问数据库的编码
	mysql_query("set names utf8",$conn) or die(mysql_errno());
	//选择数据库
	mysql_select_db($dbname,$conn) or die(mysql_errno());

        //查询最新的10条记录
        $sql = "select title,id from blog order by time desc limit 0,10";
        $res = mysql_query($sql,$conn);

        //打印结果
        while($row=mysql_fetch_assoc($res)){
		$id=$row['id'];
                echo "<li><a href='blogPage.php?id=$id'>{$row['title']}</li>";
        }

        //关闭资源和数据库
        mysql_free_result($res);
        mysql_close($conn);
?>
                </ul>
        </div>
	</div>
	<div id="footer">
		<p>Copyright &#169;2012 Powered by <a href="http://code.google.com/p/simbs/">simbs</a> </p>
	</div>
</div>
</body>
</html>
